package org.pine.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.pine.api.enums.ResultCodeEnum;
import org.pine.common.exception.PineException;

import java.util.Arrays;
import java.util.Objects;

/**
 * 角色类型枚举
 *
 * @author pine
 * @version v1.0
 * @since 2025-04-19 14:33
 */
@AllArgsConstructor
@Getter
public enum RoleTypeEnum implements DatabaseBaseEnum {

    SUPER_ADMIN(1, "超级管理员角色"),
    ADMIN(2, "普通管理员角色"),
    COMMON(3, "普通角色");

    @EnumValue
    private final Integer code;
    private final String desc;

    public static RoleTypeEnum of(Integer code) {
        return Arrays.stream(RoleTypeEnum.values()).filter(roleTypeEnum -> Objects.equals(roleTypeEnum.code, code))
                .findAny()
                .orElseThrow(() -> new PineException(ResultCodeEnum.DATA_NOT_FOUND_EXCEPTION.getCode(), "角色类型编码不存在"));
    }
}
